package com.sanley.coronavirus.service.iml;

import com.github.pagehelper.PageHelper;
import com.sanley.coronavirus.bo.CheckOutBO;
import com.sanley.coronavirus.dao.CheckOutDao;
import com.sanley.coronavirus.dao.UserDao;
import com.sanley.coronavirus.entity.CheckOut;
import com.sanley.coronavirus.service.CheckOutService;

import java.sql.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: bonbon
 * @Date: 2021/4/15 14:32
 */
@Service
public class CheckOutImpl implements CheckOutService {

    @Autowired
    private CheckOutDao dao;

    @Autowired
    private UserDao userDao;

    @Override
    public void add(String username, CheckOutBO checkOutBO) {
        String name = userDao.selectNameByUsername(username);
        int baseId = userDao.getBaseIdByUsername(username);
        CheckOut checkOut = new CheckOut().setBaseId(baseId).setCurrentPosition(checkOutBO.getCurrentPosition()).setBodyTemperature(checkOutBO.getBodyTemperature())
                .setHealthState(checkOutBO.getHealthState()).setIsToHighArea(checkOutBO.getIsToHighArea()).setIsTouch(checkOutBO.getIsTouch())
                .setRemarks(checkOutBO.getRemarks()).setName(name).setCheckOutDate(new Date(System.currentTimeMillis()));
        dao.add(checkOut);
    }

    @Override
    public List<CheckOut> findAll(int page, int size) {
        PageHelper.startPage(page, size);
        return dao.findAll();
    }

    @Override
    public List<CheckOut> findByName(String name) {
        return dao.findByName(name);
    }

    @Override
    public List<CheckOut> getCheckOutById(String username) {
        Integer baseId = userDao.getBaseIdByUsername(username);
        return dao.findById(baseId);
    }
}
